package com.dyoud.api.user.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.dyoud.api.ReturnInfo;
import com.dyoud.api.user.dto.CheckBankInfoDto;
import com.dyoud.api.user.service.BankApiService;
import com.dyoud.core.ResponseBean;
import com.dyoud.user.api.response.JuheIdentifireInfoResponse;

/**
 * 银行卡控制器
 * 
 * @author Jonathan
 * @date 2018/03/01
 *
 */
@RestController
@RequestMapping("banks")
public class BankController {

    @Resource
    private BankApiService bankApiService;

    /**
     * 检查银行卡是否正确
     * 
     * @param checkBankInfoDto
     * @return
     */
    @RequestMapping(value = "check", method = RequestMethod.GET)
    public ResponseBean bankCheck(CheckBankInfoDto checkBankInfoDto) {
        ResponseBean response = new ResponseBean();
        JuheIdentifireInfoResponse juheIdentifireInfoResponse = bankApiService.check(checkBankInfoDto);
        if (juheIdentifireInfoResponse.hasError()) {
            return response.fail(juheIdentifireInfoResponse.getReason());
        }
        if (!juheIdentifireInfoResponse.getResult().isMatch()) {
            return response.fail(ReturnInfo.BANK_NOT_MATCH_CODE, ReturnInfo.BANK_NOT_MATCH_MSG);
        }
        return new ResponseBean().success();
    }

}
